package edu.tms.dao;

import java.util.List;
import java.util.Map;

import edu.tms.bean.Album;
import edu.tms.crud.JdbcUtil;
import edu.tms.dao.common.CommnonDao;


/**
 * 相册表Dao
 * @author Administrator
 *
 */
public class AlbumDaoImp implements CommnonDao<Album>{
	/**
	 * 保存相册
	 * 
	 */
	@Override
	public long save(Album value) throws Exception {
		String sql="INSERT INTO t_album(album_name,album_url,create_time,album_state ) ";
		sql+="VALUES(?,?,?,?)";
		return JdbcUtil.insertAuto(sql,value.getAlbumName(),
				value.getAlbumUrl(),
				value.getCreateTime(),
				value.getAlbumState());
	}
	
	/**
	 * 修改
	 */
	@Override
	public int update(Album value) throws Exception {
			Album album = value;
			String sql="UPDATE t_album SET album_name=? ,album_url=?,create_time=?,album_state=?  where album_id=?";
			int Number=(int) JdbcUtil.update(sql,
					album.getAlbumName(),
					album.getAlbumUrl(),
					album.getCreateTime(),
					album.getAlbumState(),
					album.getAlbumId());
			return Number;
	}
	
	/**
	 * 删除内容
	 * 照片存储表t_picture，特色展示板块表 t_class_activity
	 * 学生个人展示板块 t_school_life
	 * @param value
	 * @throws Exception
	 */
	@Override
	public int delete(Album value) throws Exception {
		Album album=null;
		album=(Album)value;
		String sql="UPDATE t_album SET album_state=?  where album_id=? or album_name=?";
		int Number=(int) JdbcUtil.update(sql,
				album.getAlbumState(),
				album.getAlbumId(),
				album.getAlbumName());
		return Number;

	}
	/**
	 * 查找所有的内容
	 * 照片存储表t_picture，特色展示板块表 t_class_activity
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<Album> findAll(int pageNo, int pageSize) throws Exception {
		// TODO Auto-generated method stub
		String sql="select * from t_album  limit ?,?";
		return JdbcUtil.query(Album.class, sql, (pageNo-1)*pageSize,pageSize);
	}

	/**
	 * String 对应  数据库 列名（comment)
	 * Object 对应相应列名值
	 * 返回的是所查找的类中的数据。方便EXCEL导出
	 */
	@Override
	public List<Map<String,Object>> getMapList() throws Exception {
		// TODO Auto-generated method stub
		return null;
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public List<Album> findAll(Object key, int pageNo, int pageSize) throws Exception {
		// TODO Auto-generated method stub
		String sql="select * from t_album  WHERE album_id= ? or album_name=? or album_url=?  limit ?,?";
		return JdbcUtil.query(Album.class, sql,key,key,key, (pageNo-1)*pageSize,pageSize);
		
	}
	@Override
	public Album findByKey(Object key) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}
}
